package com.example.controller;

import com.example.domain.Result;
import com.example.domain.Soil;
import com.example.service.SoilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/soils")
public class SoilController {

    @Autowired
    private SoilService soilService;

    @GetMapping
    public Result getAll(){
        return new Result(true, soilService.getAll());
    }

    @GetMapping("{soilId}")
    public Result getById(@PathVariable Integer soilId){
        return new Result(true,soilService.getById(soilId));
    }

    @PostMapping
    public Result add(@RequestBody Soil soil) {
        boolean code = soilService.add(soil);
        return new Result(code);
    }

    @PutMapping
    public Result update(@RequestBody Soil soil){
        boolean code = soilService.update(soil);
        return new Result(code);
    }

    @DeleteMapping("{soilId}")
    public Result delete(@PathVariable Integer soilId){
        boolean code = soilService.delete(soilId);
        return new Result(code);
    }
}
